package com.ce.pms.report.service;

import java.util.ArrayList;
import java.util.List;

import com.ce.pms.charge.service.IAccountService;
import com.ce.pms.common.model.SysrefcodeDO;
import com.ce.pms.common.util.StringAnalysiUtil;
import com.ce.pms.house.dao.IExamineApproveDao;
import com.ce.pms.house.dao.IGoOutDao;
import com.ce.pms.house.model.ExamineApproveDomain;
import com.ce.pms.house.model.GoOutDomain;
import com.ce.pms.house.model.GoodsRecordDomain;
import com.ce.pms.report.vo.GoOutReportVO;
import com.ce.report.entity.CEReportDataSet;
import com.ce.report.exception.CEReportException;
import com.ce.report.service.ICEReportDataSetService;
import com.ce.report.vo.ReportsQueryBaseVo;
import com.ce.util.BlankUtil;
/**
 * 功能描述: 退伙记录打印功能类
 * <p>版权所有：中企动力
 * <p>未经本公司许可，不得以任何方式复制或使用本程序任何部分
 *
 * @author  胡煦
 * Create on:2008-9-12
 * Edit author:
 * Edit on:
 * 修改原因：
 */
public class GoOutReportService implements ICEReportDataSetService{

	public CEReportDataSet getReportDataSet(ReportsQueryBaseVo arg) throws CEReportException {
		GoOutReportVO queryVO = (GoOutReportVO) arg;
		GoOutReportVO reportVO = this.create(queryVO.getGoOutId());
		List<GoOutReportVO> list = new ArrayList<GoOutReportVO>();
		list.add(reportVO);

		return new CEReportDataSet(list);
	}

//	private GoOutReportVO create(){
//		GoOutReportVO reportVO = new GoOutReportVO();
//
//	}
//	public List<BaseDataVo> getDataList(Map<?, ?> arg0) {
//		String goId = ReportHelper.getMapValue("goOutId", arg0);
//		Long goOutId =  Long.parseLong(goId);
//		List<BaseDataVo> list = new ArrayList<BaseDataVo>();
//		list.add(this.create(goOutId));
//		return list;
//	}
//
//	/* (non-Javadoc)
//	 * @see com.ce.util.openreport.service.IReportService#getDataPage(java.util.Map)
//	 */
//	public ReportPage getDataPage(Map<?, ?> arg0) {
//		String goId = ReportHelper.getMapValue("goOutId", arg0);
//		Long goOutId =  Long.parseLong(goId);
//		ReportPage page = new ReportPage();
//		List<BaseDataVo> list = new ArrayList<BaseDataVo>();
//		list.add(this.create(goOutId));
//		page.setTatalPage(1);
//		page.setDataList(list);
//
//		return page;
//	}

	private GoOutReportVO create(Long goOutId){

		GoOutReportVO goOutReportVO = new GoOutReportVO();
		GoOutDomain goOutDomain = goOutDao.findById(goOutId);
		//客服经理审核记录
		ExamineApproveDomain clientExamineApprove = examineApproveDao.getExamineApproveBy(goOutId, SysrefcodeDO.HM_EXAMINE_APPROVE_USER_ROLE_CLIENT);
		//财务经理审核记录
		ExamineApproveDomain financeExamineApprove = examineApproveDao.getExamineApproveBy(goOutId, SysrefcodeDO.HM_EXAMINE_APPROVE_USER_ROLE_FINANCE);
		goOutReportVO.setChargeTotal(accountService.getBalance(goOutDomain.getHouse().getKeyword()));
		goOutReportVO.setAmmeterReading(goOutDomain.getCopyMeterData2()==null?null:goOutDomain.getCopyMeterData2().getReading());
		goOutReportVO.setWaterCopyReading(goOutDomain.getCopyMeterData1()==null?null:goOutDomain.getCopyMeterData1().getReading());
		goOutReportVO.setGasMeterReading(goOutDomain.getCopyMeterData3()==null?null:goOutDomain.getCopyMeterData3().getReading());
		goOutReportVO.setCheckDate(goOutDomain.getCheckDate());
		goOutReportVO.setCheckInfo(goOutDomain.getHouseDesc());
		goOutReportVO.setOwersName(goOutDomain.getClients());
		goOutReportVO.setClientOpinion(clientExamineApprove.getNotion());
		goOutReportVO.setClientDate(clientExamineApprove.getExamineDate());
		goOutReportVO.setFinanceOption(financeExamineApprove.getNotion());
		goOutReportVO.setFinanceDate(financeExamineApprove.getExamineDate());
		goOutReportVO.setChecker(goOutDomain.getChecker());
		goOutReportVO.setHouseNumber(goOutDomain.getHouse().getHouseNumber());
		goOutReportVO.setGoOutDate(goOutDomain.getOutDate());
		//设置移交物品
		if(!BlankUtil.isBlank(goOutDomain.getGoods())){
			List<Long> list = new ArrayList<Long>();
			List<String> strList = new ArrayList<String>();
			for(GoodsRecordDomain recordDomain :goOutDomain.getGoods()){
				list.add(recordDomain.getKeyword());
				strList.add(recordDomain.getName());
			}
			Object[] strings = strList.toArray();
			goOutReportVO.setGoods(StringAnalysiUtil.portfolioFormattedString(strings));
		}
		return goOutReportVO;
	}

	private IGoOutDao goOutDao;
	private IAccountService accountService;
	private IExamineApproveDao examineApproveDao;

	/**
	 * @param goOutDao the goOutDao to set
	 */
	public void setGoOutDao(IGoOutDao goOutDao) {
		this.goOutDao = goOutDao;
	}

	/**
	 * @param accountService the accountService to set
	 */
	public void setAccountService(IAccountService accountService) {
		this.accountService = accountService;
	}

	/**
	 * @param examineApproveDao the examineApproveDao to set
	 */
	public void setExamineApproveDao(IExamineApproveDao examineApproveDao) {
		this.examineApproveDao = examineApproveDao;
	}

}
